package xiegd.com.springbootuse.demo.delay;

import java.util.concurrent.DelayQueue;

/**
 * @Author: xieguangda
 * @Description:
 * @Date: 2023/9/8 14:06
 */
public class MyDelayTest {

    private static DelayQueue<CancelSendOrderDelay> waitReceiveCancelQueue = new DelayQueue<>();

    public static void main(String[] args) {

        //timeout是需要弹出队列的时间戳
        CancelSendOrderDelay waiReceibeDlay = new CancelSendOrderDelay(1, 1694154589000L);
        waitReceiveCancelQueue.offer(waiReceibeDlay);

        CancelSendOrderDelay waiReceibeDlay2 = new CancelSendOrderDelay(2, 1694154889000L);
        waitReceiveCancelQueue.offer(waiReceibeDlay2);
        while (true) {
            System.out.println("我是开始：");
            try {
                CancelSendOrderDelay take = waitReceiveCancelQueue.take();
                if(take != null){
                    System.out.println("对象的属性：" + take.getTimeOut() + "," + take.getId());
                }else{
                    System.out.println("对象为空；");
                }

            } catch (Exception e) {
                System.out.println("我是报错噢噢噢噢");
            }
            System.out.println("我是开始结束");
        }

    }

}
